<template>
  <div class="personal_purse">
    <!-- <my-header :showBack="true" title="奖金"></my-header> -->
		<div class="ass_top">
      <div class="head_top">
        <div>
          <i class="icon-arrow-left iconfont"  @click="goBack"></i>
        </div>
        <div>{{$t("lang.redemptionCenter")}}</div>
        <div class="rightmenu">
          <!--  -->
        </div>
      </div>
    <div class="all_ass">
      <p>{{$t("lang.UseRegisterPoint")}}</p>
      <h3>{{parseFloat(MyAssData.registerPoint).toFixed(3)||"0.000"}}</h3>
      <!-- <p>兑换人：<b>0.00</b></p> -->
    </div>
    <div class="as_three">
      <div>
        <p>{{parseFloat(MyAssData.usePoint).toFixed(3)||"0.000"}}</p>
        <p>{{$t("lang.UsePoints")}}</p>
      </div>
      <div class="divborder">
        <p>{{parseFloat(MyAssData.useStock).toFixed(3)||"0.000"}}</p>
        <p>{{$t("lang.UseStock")}}</p>
      </div>
      <div class="divborder">
        <p>{{parseFloat(MyAssData.activationPoint).toFixed(3)||"0.000"}}</p>
        <p>{{$t("lang.UseActivationPoint")}}</p>
      </div>
    </div>
    </div>
    <div>
		<!-- 02 -->
    <!-- POST /api/coin/selectStockList -->
    <van-list v-show="recordList.length>0" v-model="loading" :finished="finished"  @load="onLoad" finished-text="没有更多了" class="trad_list"> 
			<ul class="trad_list">
				<li v-for="item in recordList" 
          :key="item.index">
					<div slot="title" class="jytime">
						<div class="nflex top_contitle">
							<h3>{{$t('lang.No')}}：{{item.id}} | {{$t('lang.Trname')}}：{{item.trueName}}  | {{$t('lang.MemberName')}}：{{item.saleNumber}}</h3>
							<p class="tipred" @click="buyBtn(item)">{{$t('lang.buy')}}<span class="iconfont  icon-arrow-right"></span></p>
						</div>
						<div class="nflex">
							<p>{{$t('lang.AmountMon')}}</p>
							<p class="">{{item.tradeAmount}}</p> 
						</div>
            <div class="nflex">
							<p>{{$t('lang.Time')}}</p>
							<p class="">{{item.createTime}}</p>
						</div>
					</div>
				</li>
			</ul>
    </van-list>
      <div class="no_data" v-show="recordList.length==0">{{$t("lang.NoData")}}</div>
    </div>
    <!-- 弹出层 -->
    <van-dialog
        v-model="show"
        show-cancel-button
        :before-close="beforeClose"
        :confirm-button-text="$t('lang.confirm')"
        :cancel-button-text="$t('lang.cancel')"
      >
      <p id= "sure">是否确认购买</p>
        <!-- <van-field
          v-model="payWord"
          type="password"
          :label="$t('lang.scccPword')"
          :placeholder="$t('lang.enterSpword')"
          @blur="blur"
        /> -->
      </van-dialog>
  </div>
</template>

<script>
import header from "@/components/header";
import { Toast,List } from 'vant';
import ClipboardJS from 'Clipboard'


export default {
  components: {
    "my-header": header,
    
  }, 
  // inject:['reload'],/
  data(){
    return{
			userInfo:{},
			
			activeName: '1',
			activeNames: ['0'],
		  MyAssData:{},
      showLeftProp: false,
      show:false,
      JifenNum:"",
      buyID:"",
      payWord:"",
      loading: false,
      finished: false,
      recordList: [],
      searchData: {
        pageNo: 1, //当前页
        pageSize: 30, //每页30条
      },
    }
  },
  filters: {
    formatDate(time) {
      var date = new Date(time);
      return timeFormat.formatDate(date, "yyyy.MM.dd hh:mm");
    }
  },
  mounted(){
    this.selectAccount();
    this.init();
    console.log(2)
  },
  methods:{
    // 弹出层的input框失去焦点时触发
    blur(){
      console.log("失去焦点");
      window.scrollTo(0,0);
    },
		showProp(){
      this.showLeftProp=true;
    },
    closeProp(){
      this.showLeftProp=false;
    },
    selectAccount(){
      // 个人资产
      this.$ajax(this.$api.selectAccount).then(
        res=>{
          if(res.code==0){
            this.MyAssData=res.msg;
          }
        }
      )
    },
    init() {
      this.searchData.pageNo = 1;
      this.loading = true;
      this.$ajax(this.$api.selectStockList, this.searchData).then(res => {
        if (res.code === 0) {
          if (res.msg && res.msg.list.length > 0) {
            this.recordList = res.msg.list;
            this.finished = this.searchData.pageNo == res.msg.lastPage;
            this.loading = false;
            console.log(this.finished,333333333333)
          }else{
            this.recordList = [];
          }
        } else {
          this.recordList = [];
        }
        console.log(this.finished,this.loading,2222222222222)
      });
    },
    onLoad: function() {
      this.loading = false;
      console.log(this.loading,this.finished,4444444444444)
      // console.log(this.loading)
      this.searchData.pageNo += 1;
      this.$ajax(this.$api.selectStockList, this.searchData).then(res => {
        this.loading = true;
        if (res.code === 0) {
          if (res.msg && res.msg.list.length > 0) {
            this.recordList = res.msg.list.concat(this.recordList)
            console.log(this.recordList.length)
            this.finished = this.searchData.pageNo == res.msg.lastPage;
            this.loading = false;
            console.log(this.loading,this.finished,22222222)
          }
        }
         this.loading = false;
      });
    },
    buyBtn(item){
      this.buyID=item.id;
      // buyStock
      this.show=true;
      this.payWord="";
    },
    beforeClose(action, done) {
      if (action === 'confirm') {
      //   if(this.payWord==""){
      //     Toast({ message: this.$t('lang.enterSpword'), position: "bottom" });
      //     done(false)
      //     return
      //   }
      //   if(!this.$validator.isPassword(this.payWord)){
      //   Toast({message: this.$t('lang.truepayPass'),position: "bottom"});
      //   done(false)
      //   return;
      // }
      this.$ajax(this.$api.buyStock, {id:this.buyID,payPass:""}).then(res => {
        this.loading = true;
        if (res.code === 0) {
          Toast({ message: this.$t('lang.CZsuccessful'), position: "bottom" });
          this.show=false;
          this.payWord="";
          this.selectAccount();
          setTimeout(this.init(),100);
          this.loading = true;
          //this.init();
          //this.reload();
        } else {
          this.show=false;
          this.payWord="";
          Toast({ message: res.msg, position: "bottom" });
          this.selectAccount();
          this.init();
          setTimeout(this.init(),2500);
        }
        this.loading = false;
      });
        setTimeout(done, 100);
      } else {
        done();
      }
    }
  }
}
</script>

<style lang='less' scoped>
#sure{
  text-align: center;
  padding:20px 0px;
}
.child-view {
  position: relative;
}
.personal_purse{background: #f6f6f6;}
.ass_top{background: url(../../assets/img/my/grzx_dhzx.png) 0 0 no-repeat;background-size: 100%}
.all_ass{
  text-align: center;padding:30px 0;
  h3{color: #E1AF56;font-size: 24px;line-height: 30px;}
	p{color: #AA7A24;padding: 5px 0;}
	b{color: #E1AF56;}
}
// head_top
.head_top{
	width: 100%;
  height: 44px;
	line-height: 44px;
  font-size: 16px;
  color: #ffffff;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  background: transparent;      
}
.head_top .menu{font-size: 20px;}
.head_top i{
  padding:10px;
  font-size: 24px;
}
.head_top div:nth-child(1) {
  width:20%;
  box-sizing: border-box;
}
.head_top div:nth-child(2) {
  width:60%;
  text-align:center;
}
.head_top div:nth-child(3) {
  width:20%;
  text-align:center;
  font-size:12px;
}
// 
.trad_list{
	background: #f6f6f6;margin-top:0px;
		h3{color: #333333;line-height: 26px;}
		li{margin-bottom: 10px;background: #ffffff;box-sizing: border-box;padding: 10px 12px;}
		.nflex{display: flex;justify-content:space-between ;padding-top: 0px;
      p{line-height: 20px;color: #999999;}
			span{color: #FF5458;}
			.npadd{padding: 15px 0;}
			.tiphui{color: #999999;}
			.tipred{color: #FF5458;}
      .tipgren{color: #00BA4F;}
    }
    .top_contitle{border-bottom: 1px solid #eeeeee; }
		.buybtn{color: #FF4954;border: 1px solid #FF4954;border-radius: 20px;padding: 0 6px ;}		
}
.jytime{
	h3{color: #333333;font-size: 14px;}
	p{color: #CCCCCC;}
	}
// 新加
.as_three{
  display: flex;padding: 5px 0;background:#7e0202;position: relative;
  div{
    text-align: center;flex:1;
    p:nth-child(1){color:#E1AF56;}
    p:nth-child(2){color:#AA7A24;}
  }
  .divborder:after {
    position: absolute;
    /* width: 100%; */
    height: 25px;
    top: 12px;
    // left: 0;
    display: block;
    border-left: 1px solid #AA7A24;
    // border-right: 1px solid #AA7A24;
    content: ' ';
  } 
}
</style>
